/*
 * Project: yygh-parent
 *
 * File Created at 2023/6/24
 *
 * 自定义时间格式代替DATE标签：2023-06-24 19:09:19:09
 */
package com.atguigu.yygh.order.service.impl;


import com.atguigu.yygh.common.exception.HospitalException;
import com.atguigu.yygh.common.result.ResultCodeEnum;
import com.atguigu.yygh.order.mapper.HospitalSetMapper;
import com.atguigu.yygh.model.hosp.HospitalSet;
import com.atguigu.yygh.order.service.HospitalSetService;
import com.atguigu.yygh.vo.order.SignInfoVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 用户名
 * @Type HospitalSetServiceImpl.java
 * @Desc
 * @date 2023/6/24 19:09
 */
@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {
    @Autowired
    HospitalSetMapper hospitalSetMapper;

    @Override
    public String getSignKey(String hoscode) {
        HospitalSet byHoscode = this.getByHoscode(hoscode);
        if(byHoscode==null){
            throw new HospitalException(ResultCodeEnum.HOSPITAL_OPEN);
        }

        if(byHoscode.getStatus().intValue()==0){
            throw new  HospitalException(ResultCodeEnum.HOSPITAL_LOCK);
        }
        return byHoscode.getSignKey();
    }

    @Override
    public SignInfoVo findSignVo(String hostCode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        QueryWrapper<HospitalSet> hoscode = wrapper.eq("hoscode", hostCode);

        HospitalSet hospitalSet = hospitalSetMapper.selectOne(hoscode);
        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());

        return signInfoVo;
    }

    private HospitalSet getByHoscode(String hoscode) {

       return hospitalSetMapper.selectOne(new QueryWrapper<HospitalSet>().eq("hoscode", hoscode));

    }
}


/**
 * Revision history
 * -------------------------------------------------------------------------
 * <p>
 * Date Author Note
 * -------------------------------------------------------------------------
 * 2023/6/24 用户名 create
 */ 
